<?php

error_reporting(E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR);
require('./roots.php');
require($root_path.'include/inc_environment_global.php');

# Set break file
require('include/inc_breakfile.php');


# If cache must be deactivated, set $force_no_cache to true
$force_no_cache=1;

define('LANG_FILE','interconsulta.php');
define('NO_2LEVEL_CHK',1);
require_once('include/inc_local_user.php');
require_once($root_path.'include/inc_front_chain_lang.php');
require_once($root_path.'include/care_api_classes/class_core.php');
$core=new Core;

 /**
 * LOAD Smarty
 */

 require_once($root_path.'gui/smarty_template/smarty_care.class.php');
 $smarty = new smarty_care('common');

if($parent_admit) $sTitleNr= ($_SESSION['sess_full_en']);
	else $sTitleNr = ($_SESSION['sess_full_pid']);

# Title in the toolbar
$action="interconsulta-mias.php".URL_APPEND."&target=todos";
$msj = '';
global $_POST;
extract($_POST);

// echo "<pre>";
// var_dump($_POST);
// echo "</pre>";


$login=$_SESSION['sess_login_userid'];

$searchprompt=$LDSearchWordPrompt;

$smarty->assign('action', $action);

$smarty->assign('searchprompt', $searchprompt);

$smarty->assign('sToolbarTitle',$LDMisInter);

$smarty->assign('breakfile',$breakfile);

# Window bar title
$smarty->assign('title',$LDMisInter);

# Onload Javascript code
$smarty->assign('sOnLoadJs','onLoad="document.searchform.searchkey.select()"');

# hide return button
$smarty->assign('pbBack',FALSE);


# Load tabs
$target='todos';
require('./gui_bridge/default/gui_tabs_interconsulta.php');

 # Buffer page output
$sTemp = ob_get_contents();
ob_end_clean();
$sTemp = '';
ob_start();

include_once($root_path.'include/care_api_classes/class_interconsulta.php');
$inter_mias=new Interconsulta;
$especialidades = $inter_mias->loadEspecialidades();

$combo_esp = "<select name='id_especialidad'><option value='0' selected>$LDSelect</option>";
if (count($especialidades))
{
    foreach ($especialidades as $esp)
    {
        if ($id_especialidad==$esp['id'])
        {
            $combo_esp .= "<option value='" . $esp['id'] . "' selected>";

	if ($esp["descripcion"]=='Medicina Interna'){
		$combo_esp.=$LDMedicinaInterna;
	}elseif ($esp["descripcion"]=='Pediatria'){
		$combo_esp.=$LDPediatria;
	}elseif ($esp["descripcion"]=='Gineco-obstetra'){
		$combo_esp.=$LDGinecoObstetra;
	}elseif ($esp["descripcion"]=='Cirugia'){
		$combo_esp.=$LDCirugia;
	}elseif ($esp["descripcion"]=='Cardiologia'){
		$combo_esp.=$LDCardiologia;
	}elseif ($esp["descripcion"]=='Dermatologia'){
		$combo_esp.=$LDDermatologia;
	}else{
		$combo_esp.=$esp["descripcion"];
	}
	
	"</option>";
        }
        else
        {
        $combo_esp .= "<option value='" . $esp['id'] . "'>";
	if ($esp["descripcion"]=='Medicina Interna'){
		$combo_esp.=$LDMedicinaInterna;
	}elseif ($esp["descripcion"]=='Pediatria'){
		$combo_esp.=$LDPediatria;
	}elseif ($esp["descripcion"]=='Gineco-obstetra'){
		$combo_esp.=$LDGinecoObstetra;
	}elseif ($esp["descripcion"]=='Cirugia'){
		$combo_esp.=$LDCirugia;
	}elseif ($esp["descripcion"]=='Cardiologia'){
		$combo_esp.=$LDCardiologia;
	}elseif ($esp["descripcion"]=='Dermatologia'){
		$combo_esp.=$LDDermatologia;
	}else{
		$combo_esp.=$esp["descripcion"];
	}

	 " </option>";
        }
    }
}
$combo_esp .= "</select>";

switch($estatus)
{
    case 0:
        $combo_st = "<select name='estatus'><option value='0' selected>$LDSelect</option><option value='1'>$LDAsignada</option><option value='2'>$LDEspera</option></select>";
        break;
    case 1:
        $combo_st = "<select name='estatus'><option value='0'>$LDSelect</option><option value='1' selected>$LDAsignada</option><option value='2'>$LDEspera</option></select>";
        break;
    case 2:
        $combo_st = "<select name='estatus'><option value='0'>$LDSelect</option><option value='1'>$LDAsignada</option><option value='2' selected>$LDEspera</option></select>";
        break;
}
$consultados = $inter_mias->getValueByConsultado($login, $id_especialidad, $estatus, $interconsultante, $fechac, $fechar);
$consultantes = $inter_mias->getValueByConsultante($login, $id_especialidad, $estatus, $interconsultado, $fechac, $fechar);

if (!count($consultados) && !count($consultantes) && !strcmp($mode, "search"))
{
    $msj =$LDNoFound;
}
?>
<script language="javascript">
    function checkSubmit()
    {
        document.interconsulta.mode.value = "search";
        return true;
    }
</script>

<table cellspacing="1" cellpadding="2" border="0" align="center">
<?php
	# Load the interconsultas
	if($consultantes != NULL){
?>
		<tr class="reg_list_titlebar">
			<td align="center"><?php echo $LDNombrePaciente; ?></td>
			<td align="center"><?php echo $LDEstablecimineto; ?></td>
			<td align="center"><?php echo $LDMedicoConsul; ?></td>
			<td align="center"><?php echo $LDMedicoConsultado; ?></td>
			<td align="center"><?php echo $LDAccion; ?></td>
		</tr>
<?php
		$pos=1;
		foreach($consultantes as $consultante){
?>
		<tr class="wardlistrow<?=$pos?>">
			<td align="center"><?=$consultante['paciente']?></td>
			<td align="center"><?=$consultante['establecimiento']?></td>
			<td align="center"><?=$consultante['consultante']?></td>
<?php
			if ($consultante['consultado']){
?>
			<td align="center"><?=$consultante['consultado']?></td>
<?php
			}else{
?>
			<td align="center" style="color:red;"><?php echo $LDEspera; ?></td>
<?php
			}
?>
			<td align="center"><a href="<?=$root_path?>modules/interconsulta/interconsulta-consultar.php<?=URL_APPEND?>&id=<?=$consultante['id']?>"><input type="image" <?=createLDImgSrc($root_path,'ok_small.gif','0')?>  alt="Consultar"/></a></td>
		</tr>
<?php
			if ($pos==1){$pos=2;
			}else{	$pos=1;	}
		}
	}

	if($consultados != NULL){
		if($consultantes == NULL){
?>
		<tr class="reg_list_titlebar">
			<td align="center"><?php echo $LDNombrePaciente; ?></td>
			<td align="center"><?php echo $LDEstablecimineto; ?></td>
			<td align="center"><?php echo $LDMedicoConsul; ?></td>
			<td align="center"><?php echo $LDMedicoConsultado; ?></td>
			<td align="center"><?php echo $LDAccion; ?></td>
		</tr>
<?php
		$pos=1;
		}
		foreach($consultados as $consultado){
?>
		<tr class="wardlistrow<?=$pos?>">
			<td align="center"><?=$consultado['paciente']?></td>
			<td align="center"><?=$consultado['establecimiento']?></td>
			<td align="center"><?=$consultado['consultante']?></td>
			<td align="center"><?=$consultado['consultado']?></td>
			<td align="center"><a href="<?=$root_path?>modules/interconsulta/interconsulta-consultar.php<?=URL_APPEND?>&id=<?=$consultado['id']?>"><input type="image" <?=createLDImgSrc($root_path,'ok_small.gif','0')?>  alt="Consultar"/></a></td>
		</tr>
<?php
			if ($pos==1){$pos=2;
			}else{	$pos=1;	}
		}
	}

	if($consultados==NULL && $consultantes==NULL){
?>
		<h3 style="color:red;" ><?=$LDSinInter?></h3>
<?php
	}
?>
</table>

	
<?php
$sTemp = ob_get_contents();
ob_end_clean();

$smarty->assign('sEspecialidad', $LDEspecialidad);
$smarty->assign('especialidadSelect', $combo_esp);

$smarty->assign('sEstatus', $LDStatus);
$smarty->assign('estatusSelect', $combo_st);

$smarty->assign('cual', 0);
// $smarty->assign('sInterconsultante', $LDInterconsultante);
// $smarty->assign('intereInput', $intere);
// 
// $smarty->assign('sInterconsultado', $LDInterconsultado);
// $smarty->assign('interoInput', $intero);

include_once('../../include/inc_date_format_functions.php');
require_once ('../../js/jscalendar/calendar.php');
$calendar = new DHTML_Calendar('../../js/jscalendar/', ''.$lang.'', 'calendar-system', true);
$calendar->load_files();


$smarty->assign('sFechac', $LDDateC);
$smarty->assign('sCalendarCInput',$calendar->show_calendar($calendar,'dd/MM/yyyy','fechac',$fechac));

$smarty->assign('sFechar', $LDDateR);
$smarty->assign('sCalendarRInput',$calendar->show_calendar($calendar,'dd/MM/yyyy','fechar',$fechar));

$smarty->assign('sHiddenInputs','<input type="image"'.createLDImgSrc($root_path,'searchlamp.gif','0','absmiddle').'><input type="hidden" name="lang" value="'.$lang.'"><input type="hidden" name="mode" value="">');

$smarty->assign('msj', $msj);


# Assign the buffer output  to main frame template
$smarty->assign('sMainDataBlock',$sTemp);
$smarty->assign('sMainBlockIncludeFile','interconsulta/main_plain.tpl');

 /**
 * show Template
 */
 $smarty->display('common/mainframe.tpl');


?>

